﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using IronCow.Rest;

namespace IronCow.UnitTests
{
    [TestFixture]
    public class TestDisabledSyncing
    {
        [Test]
        public void TestContactGroups()
        {
            Rtm rtm = new Rtm(new DisabledRestClient());
            rtm.DisableSyncing();

            Assert.That(rtm.ContactGroups, Has.Count(0));
            Assert.That(rtm.Contacts, Has.Count(0));

            var contactGroup = new ContactGroup("Staff");
            rtm.ContactGroups.Add(contactGroup);
            Assert.That(rtm.ContactGroups, Has.Count(1));
            Assert.AreSame(contactGroup, rtm.ContactGroups[0]);

            Assert.That(contactGroup.Contacts, Has.Count(0));
            var contact = new Contact("omar");
            contactGroup.Contacts.Add(contact);
            Assert.That(contactGroup.Contacts, Has.Count(1));
            Assert.AreSame(contact, contactGroup.Contacts[0]);

            Assert.That(rtm.Contacts, Has.Count(1));
            Assert.AreSame(rtm.Contacts[0], contact);
        }

        [Test]
        public void TestContacts()
        {
            Rtm rtm = new Rtm(new DisabledRestClient());
            rtm.DisableSyncing();

            Assert.That(rtm.Contacts, Has.Count(0));

            var contact = new Contact("omar");
            rtm.Contacts.Add(contact);
            Assert.That(rtm.Contacts, Has.Count(1));
            Assert.AreSame(contact, rtm.Contacts[0]);
        }

        [Test]
        public void TestTaskLists()
        {
            Rtm rtm = new Rtm(new DisabledRestClient());
            rtm.DisableSyncing();

            Assert.That(rtm.TaskLists, Has.Count(0));

            var taskList = new TaskList("offline tasks");
            rtm.TaskLists.Add(taskList);
            Assert.That(rtm.TaskLists, Has.Count(1));
            Assert.AreSame(taskList, rtm.TaskLists[0]);
            Assert.AreEqual("offline tasks", taskList.Name);

            taskList.Name = "renamed";
            Assert.AreEqual("renamed", taskList.Name);
        }

        [Test]
        public void TestAddTaskToTaskList()
        {
            Rtm rtm = new Rtm(new DisabledRestClient());
            rtm.DisableSyncing();

            var taskList = new TaskList("offline tasks");
            rtm.TaskLists.Add(taskList);
            Assert.That(taskList.Tasks, Has.Count(0));

            var task = new Task("Something to do");
            taskList.AddTask(task);
            Assert.That(taskList.Tasks, Has.Count(1));

            Assert.That(string.IsNullOrEmpty(task.Url));
            task.Url = "http://www.rmilk.com";
            Assert.AreEqual("http://www.rmilk.com", task.Url);

            Assert.That(task.Tags, Has.Count(0));
            task.Tags.Add("@home");
            Assert.That(task.Tags, Has.Count(1));
            Assert.AreEqual("@home", task.Tags[0]);
        }
    }
}
